package com.taoes.simpledocker.model;

import com.taoes.simpledocker.model.enums.DockerEndpointState;
import com.taoes.simpledocker.model.enums.DockerEndpointType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotEmpty;
import java.util.Optional;


@ApiModel
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DockerEndpoint {


  @NotEmpty
  @ApiModelProperty(value = "主键,需要键入，要保证唯一,eg:default2", required = true)
  private String id;

  @ApiModelProperty(value = "docker客户端名称，eg：远程docker1")
  private String name;

  @ApiModelProperty(value = "DockerEndpointType",required = true)
  @NotEmpty
  private DockerEndpointType type;

  private DockerEndpointState state = DockerEndpointState.NORMAL;

  @ApiModelProperty(value = "docker主机地址",required = true)
  @NotEmpty
  private String host;

  @ApiModelProperty(value = "docker端口",required = true)
  @NotEmpty
  private Integer port;

  private String latestTestTime;

  private String createdAt;

  private String updatedAt;

  public String getTypeName(){
    return Optional.ofNullable(this.type).map(DockerEndpointType::getDesc).orElse("未知");
  }

  public String getStateName(){
    return Optional.ofNullable(this.state).map(DockerEndpointState::getDesc).orElse("未知");
  }
}
